import 'package:flutter/material.dart';
import 'package:flutter_base_library/index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:safe_manage/pages/alarm/alarm_type_list_page/alarm_type_list_item_widget/alarm_type_list_item_view.dart';
import 'alarm_type_list_controller.dart';

class AlarmTypeListPage extends StatelessWidget {
  final controller = Get.find<AlarmTypeListController>();
  AlarmTypeListPage({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(controller.title.value),
      ),
      body: Container(
        width: Get.width,
        color: const Color(0xFFEFEFF4),
        child: _bodyContent(context),
      ),
    );
  }

  Widget _bodyContent(BuildContext context) {
    return Column(
      children: [
        _titleContent(context),
        Expanded(
          child: _listContent(),
        ),
      ],
    );
  }

  Widget _titleContent(BuildContext context) {
    return Container(
      padding: const EdgeInsets.fromLTRB(15, 10, 15, 10),
      child: Row(
        children: [
          Expanded(
            child: GestureDetector(
              onTap: () {
                controller.select1Clicked(context);
              },
              behavior: HitTestBehavior.translucent,
              child: Container(
                height: 30,
                padding: const EdgeInsets.fromLTRB(5, 0, 5, 0),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(5),
                  border: Border.all(
                    color: const Color(0xFFBBBBBB),
                  ),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      "所在部门",
                      style: TextStyle(
                        color: const Color(0xFF101010),
                        fontSize: 12.sp,
                      ),
                    ),
                    Icon(
                      Icons.expand_more,
                      color: const Color(0xFFBBBBBB),
                      size: 20.sp,
                    ),
                  ],
                ),
              ),
            ),
          ),
          const SizedBox(width: 5),
          Expanded(
            child: GestureDetector(
              onTap: () {
                controller.select2Clicked(context);
              },
              behavior: HitTestBehavior.translucent,
              child: Container(
                height: 30,
                padding: const EdgeInsets.fromLTRB(5, 0, 5, 0),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(5),
                  border: Border.all(
                    color: const Color(0xFFBBBBBB),
                  ),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      "处理状态",
                      style: TextStyle(
                        color: const Color(0xFF101010),
                        fontSize: 12.sp,
                      ),
                    ),
                    Icon(
                      Icons.expand_more,
                      color: const Color(0xFFBBBBBB),
                      size: 20.sp,
                    ),
                  ],
                ),
              ),
            ),
          ),
          const SizedBox(width: 5),
          Expanded(
            child: GestureDetector(
              onTap: () {
                controller.select3Clicked(context);
              },
              behavior: HitTestBehavior.translucent,
              child: Container(
                height: 30,
                padding: const EdgeInsets.fromLTRB(5, 0, 5, 0),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(5),
                  border: Border.all(
                    color: const Color(0xFFBBBBBB),
                  ),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      "时间范围",
                      style: TextStyle(
                        color: const Color(0xFF101010),
                        fontSize: 12.sp,
                      ),
                    ),
                    Icon(
                      Icons.expand_more,
                      color: const Color(0xFFBBBBBB),
                      size: 20.sp,
                    ),
                  ],
                ),
              ),
            ),
          ),
          const SizedBox(width: 5),
          SizedBox(
            width: 40.w,
            height: 30,
            child: TextButton(
              onPressed: () {
                controller.resetButtonClicked();
              },
              style: const ButtonStyle(
                padding: MaterialStatePropertyAll(
                  EdgeInsets.zero,
                ),
              ),
              child: const Text(
                "重置",
                style: TextStyle(
                  height: 1,
                  fontSize: 14,
                  fontWeight: FontWeight.w400,
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _listContent() {
    return Obx(
      () => SmartRefresher(
        controller: controller.refreshController,
        enablePullDown: true,
        enablePullUp: true,
        header: Utils.customHeader,
        footer: Utils.customFooter,
        onRefresh: controller.onRefresh,
        onLoading: controller.onLoading,
        child: ListView.separated(
          physics: const BouncingScrollPhysics(),
          padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
          itemCount: controller.dataList.length,
          separatorBuilder: (BuildContext context, int index) {
            return const Divider(
              height: 10,
              color: Colors.transparent,
            );
          },
          itemBuilder: (BuildContext context, int index) {
            return GestureDetector(
              onTap: () {
                controller.itemClicked(index);
              },
              behavior: HitTestBehavior.translucent,
              child: AlarmTypeListItemWidget(
                controller.dataList[index],
                controller.type,
              ),
            );
          },
        ),
      ),
    );
  }
}
